<UserControl x:Class="WPFPhysics1.World"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:local="clr-namespace:WPFPhysics1"
		Name="world">

	<UserControl.Resources>
        <Style x:Key="NewtonBodyStyle">
            <EventSetter Event="Shape.MouseDown" Handler="myMouseButtonHandler" />
            <EventSetter Event="Shape.MouseUp" Handler="myMouseButtonHandler" />
            <EventSetter Event="Shape.MouseMove" Handler="myMouseMoveHandler"/>
            <EventSetter Event="Shape.MouseEnter" Handler="myMouseEnterHandler"/>
            <EventSetter Event="Shape.MouseLeave" Handler="myMouseLeaveHandler" />
        </Style>
        <DataTemplate DataType="{x:Type local:VehicleBody}">
			<Canvas>
				<Polygon Uid="{Binding Bodyid}" Points="{Binding Points}" Style="{StaticResource NewtonBodyStyle}">
					<Polygon.RenderTransform>
						<MatrixTransform Matrix="{Binding DisplayMatrix}"/>
					</Polygon.RenderTransform>
					<Polygon.Fill>
						<ImageBrush ImageSource="CarBody.png"/>
					</Polygon.Fill>
				</Polygon>
				<ItemsControl ItemsSource="{Binding Tires}">
					<ItemsControl.ItemsPanel>
						<ItemsPanelTemplate>
							<Canvas/>
						</ItemsPanelTemplate>
					</ItemsControl.ItemsPanel>
				</ItemsControl>
			</Canvas>
		</DataTemplate>

		<DataTemplate DataType="{x:Type local:Tire}">
			<Ellipse Width="{Binding Diameter}" Height="{Binding Diameter}" RenderTransformOrigin="0.5, 0.5">
				<Ellipse.RenderTransform>
					<MatrixTransform Matrix="{Binding DisplayMatrix}"/>
				</Ellipse.RenderTransform>
				<Ellipse.Fill>
					<ImageBrush ImageSource="WheelImage3.png" />
				</Ellipse.Fill>
			</Ellipse>
		</DataTemplate>

		<DataTemplate DataType="{x:Type local:PolygonBody}">
			<Polygon Uid="{Binding Bodyid}" Points="{Binding Points}" Style="{StaticResource NewtonBodyStyle}">
                <Polygon.RenderTransform>
					<MatrixTransform Matrix="{Binding DisplayMatrix}"/>
				</Polygon.RenderTransform>
                <Polygon.Fill>
                    <ImageBrush ImageSource="WoodBrush.jpg"/>
                </Polygon.Fill>
			</Polygon>
		</DataTemplate>

		<DataTemplate DataType="{x:Type local:EllipseBody}">
			<Ellipse Uid="{Binding Bodyid}" Width="{Binding Width}" Height="{Binding Height}" RenderTransformOrigin="0.5, 0.5" Style="{StaticResource NewtonBodyStyle}">
				<Ellipse.RenderTransform>
					<MatrixTransform Matrix="{Binding DisplayMatrix}"/>
				</Ellipse.RenderTransform>
				<Ellipse.Fill>
                    <ImageBrush ImageSource="OvalBrush.jpg"/>
				</Ellipse.Fill>
			</Ellipse>
		</DataTemplate>

		<DataTemplate DataType="{x:Type local:RectangleBody}">
			<Rectangle Uid="{Binding Bodyid}" Width="{Binding Width}" Height="{Binding Height}" RenderTransformOrigin="0.5, 0.5"  Style="{StaticResource NewtonBodyStyle}">
				<Rectangle.RenderTransform>
					<MatrixTransform Matrix="{Binding DisplayMatrix}"/>
				</Rectangle.RenderTransform>
                <Rectangle.Fill>
                    <ImageBrush ImageSource="{Binding BrushImageSource}"/>
                </Rectangle.Fill>
            </Rectangle>
		</DataTemplate>

		<DataTemplate DataType="{x:Type local:StaticRectangleBody}">
		  <Rectangle Uid="{Binding Bodyid}" Width="{Binding Width}" Height="{Binding Height}" RenderTransformOrigin="0.5, 0.5" Style="{StaticResource NewtonBodyStyle}">
			  <Rectangle.RenderTransform>
				  <MatrixTransform Matrix="{Binding DisplayMatrix}"/>
			  </Rectangle.RenderTransform>
                <Rectangle.Fill>
                    <ImageBrush ImageSource="SteelBrush.jpg"/>
                </Rectangle.Fill>
            </Rectangle>
		</DataTemplate>

	</UserControl.Resources>

	<ItemsControl ItemsSource="{Binding}">
		<ItemsControl.ItemsPanel>
			<ItemsPanelTemplate>
				<Canvas/>
			</ItemsPanelTemplate>
		</ItemsControl.ItemsPanel>
		<ItemsControl.RenderTransform>
			<MatrixTransform Matrix="{Binding ElementName=world, Path=ScaleTransform}"/>
		</ItemsControl.RenderTransform>
	</ItemsControl>

</UserControl>
